package com.platform.service.impl;

import com.platform.cache.J2CacheUtils;
import com.platform.dao.HomeConfigDao;
import com.platform.entity.HomeConfigEntity;
import com.platform.service.CategoryConfService;
import com.platform.service.HomeConfigService;
import com.platform.util.CateTypeEnum;
import com.platform.util.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 商城配置:APP首页配置
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2019-03-09 10:01:24
 */
@Service("homeConfigService")
public class HomeConfigServiceImpl implements HomeConfigService {
    @Autowired
    private HomeConfigDao homeConfigDao;
    @Autowired
    private CategoryConfService categoryConfService;

    @Override
    public HomeConfigEntity queryObject(Integer id) {
        return homeConfigDao.queryObject(id);
    }

    @Override
    public List<HomeConfigEntity> queryList(Map<String, Object> map) {
        return homeConfigDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return homeConfigDao.queryTotal(map);
    }

    @Override
    public int save(HomeConfigEntity homeConfig) {
        String typename = CateTypeEnum.getDesc(homeConfig.getType());
        homeConfig.setTypeName(typename);
        //清理KEY="HOME_KEY"在Redis的缓存
        J2CacheUtils.clear(Constants.REDIS_HOME);
        return homeConfigDao.save(homeConfig);
    }

    @Override
    public int update(HomeConfigEntity homeConfig) {
        String typename = CateTypeEnum.getDesc(homeConfig.getType());
        homeConfig.setTypeName(typename);
        //清理KEY="HOME_KEY"在Redis的缓存
        J2CacheUtils.clear(Constants.REDIS_HOME);
        return homeConfigDao.update(homeConfig);
    }

    @Override
    public int delete(Integer id) {
        //清理KEY="HOME_KEY"在Redis的缓存
        J2CacheUtils.clear(Constants.REDIS_HOME);
        return homeConfigDao.delete(id);
    }

    @Override
    public int deleteBatch(Integer[] ids) {
        //清理KEY="HOME_KEY"在Redis的缓存
        J2CacheUtils.clear(Constants.REDIS_HOME);
        return homeConfigDao.deleteBatch(ids);
    }
}
